<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <h1>数组常用的遍历方法</h1>

    <ul>
        <li>这是第1个li</li>
        <li>这是第2个li</li>
        <li></li>
        <li>这是第4个li</li>
        <li>这是第5个li</li>
    </ul>

    <script>
        // forEach map filter every some reduce 

        let data = [
            // goods_price 商品价格
            // goods_count 购物车的商品数量
            // goods_state 商品是否选中
            {
                id: 1,
                goods_name:
                    '班俏BANQIAO超火ins潮卫衣女士2020秋季新款韩版宽松慵懒风薄款外套带帽上衣',
                goods_img: 'https://www.escook.cn/vuebase/pics/1.png',
                goods_price: 108,
                goods_count: 1,
                goods_state: true,
            },
            {
                id: 2,
                goods_name:
                    '嘉叶希连帽卫衣女春秋薄款2020新款宽松bf韩版字母印花中长款外套ins潮',
                goods_img: 'https://www.escook.cn/vuebase/pics/2.png',
                goods_price: 129,
                goods_count: 1,
                goods_state: true,
            },
            {
                id: 3,
                goods_name:
                    '思蜜怡2020休闲运动套装女春秋季新款时尚大码宽松长袖卫衣两件套',
                goods_img: 'https://www.escook.cn/vuebase/pics/3.png',
                goods_price: 198,
                goods_count: 1,
                goods_state: false,
            }
        ]


        // 需求：得到所有goods_name的数组
        const arr = data.map((item) => item.goods_name)
        console.log(arr);
        // 需求：过滤出价格大于 130
        const arr1 = data.filter((item) => item.goods_price >= 130)
        console.log(arr1);
        // 需求：判断是否每一件商品都已经加入了购物车
        const res = data.every((item) => item.goods_state === true)
        console.log(res);
        // 需求：判断是否有商品已经加入了购物车
        const res1 = data.some((item) => item.goods_state === true)
        console.log(res1);
        // 需求：数组求和
        const arr_demo = [10, 20, 30]
        const res2 = arr_demo.reduce((prev, item) => prev + item, 0)
        console.log(res2);

        // 需求：计算所有商品的总价
        const res3 = data.reduce((prev, item) => prev + item.goods_count * item.goods_price, 0)
        console.log(res3);
        // 伪数组转真数组
        // 需求：判断所有li是否都有内容
        const lis = document.querySelectorAll('li')
        // const arr3 = Array.from(lis)
        // const res4 = arr3.every(item => item.innerHTML.length > 0)
        // console.log(res4);
        const res4 = [...lis].every(item => item.innerHTML.length > 0)
        console.log(res4);
    </script>
</body>

</html>